{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "7d266120",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['005zhiliaowan', '008kuoyinbang', '011guashi', '020yahenban', '009huiyinxiaoduqian', '022chizhenqi', '019wanqian', '007tanzhen', '010shuchiqian', '015xiaobujinqian', '003qianbijing', '018xiaoyaobei', '016hezi', '002qiangzhuangnie', '017luanyuanqian', '014dabujinqian', '001wanpan', '004pingnie', '012huojianqian', '013guchuanzhen', '006kuiyinqi', '023chuancizhen', '021jiandao', '.ipynb_checkpoints', '000none']\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "from PIL import Image\n",
    "from torchvision import transforms\n",
    "file_list = os.listdir('./imgsEnhance_5.0/train5.0/')\n",
    "print(file_list)\n",
    "\n",
    "resize256 = transforms.Resize(256)\n",
    "randomResizeCrop = transforms.CenterCrop(224)  # 中心抠图\n",
    "randomRotation = transforms.RandomRotation(180)  # 随机旋转，-180到180度之间随机选\n",
    "randomHorizontalFlip = transforms.RandomHorizontalFlip(p=0.5)  # 随机水平翻转 概率为0.5\n",
    "randomVerticalFlip = transforms.RandomVerticalFlip(p=0.5)  # 随机垂直翻转\n",
    "colorJitter = transforms.ColorJitter(brightness=0.2, contrast=0.1, saturation=0.1, hue=0.1)  # 颜色\n",
    "randomGrayscale = transforms.RandomGrayscale(p=0.025)  # 概率转换成灰度率，3通道就是R=G=B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "84599ef5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# train\n",
    "for i in file_list:\n",
    "    keyName=0;\n",
    "#     print(i)\n",
    "    subfolder = os.listdir('./imgsEnhance_5.0/train5.0/%s'%i)\n",
    "#     print(subfolder)\n",
    "    for j in subfolder:\n",
    "        for num in range(1,50):\n",
    "            if not os.path.exists('./pics5.0/train/%s' % i):\n",
    "                os.mkdir('./pics5.0/train/%s' % i)\n",
    "            keyName = keyName +1 \n",
    "            img1 = Image.open('./imgsEnhance_5.0/train5.0/'+i+'/'+j)\n",
    "            img2 = randomRotation(img1)  # 随机旋转，-75到75度之间随机选\n",
    "            img3 = randomHorizontalFlip(img2)  # 随机水平翻转 概率为0.5\n",
    "            img4 = randomVerticalFlip(img3)  # 随机垂直翻转\n",
    "            img5 = colorJitter(img4)  # 颜色\n",
    "            img6 = randomGrayscale(img5)  # 灰度\n",
    "\n",
    "            img6.save(r'./pics5.0/train/%s/%s.jpeg' % (i, keyName))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "0f4bc495",
   "metadata": {},
   "outputs": [],
   "source": [
    "# valid\n",
    "for i in file_list:\n",
    "    keyName=0;\n",
    "#     print(i)\n",
    "    subfolder = os.listdir('./imgsEnhance_5.0/train5.0/%s'%i)\n",
    "#     print(subfolder)\n",
    "    for j in subfolder:\n",
    "        for num in range(1,30):\n",
    "            if not os.path.exists('./pics5.0/valid/%s' % i):\n",
    "                os.mkdir('./pics5.0/valid/%s' % i)\n",
    "            keyName = keyName +1 \n",
    "            img1 = Image.open('./imgsEnhance_5.0/train5.0/'+i+'/'+j)\n",
    "            img2 = randomRotation(img1)  # 随机旋转，-75到75度之间随机选\n",
    "            img3 = randomHorizontalFlip(img2)  # 随机水平翻转 概率为0.5\n",
    "            img4 = randomVerticalFlip(img3)  # 随机垂直翻转\n",
    "            img5 = colorJitter(img4)  # 颜色\n",
    "            img6 = randomGrayscale(img5)  # 灰度\n",
    "\n",
    "            img6.save(r'./pics5.0/valid/%s/%s.jpeg' % (i, keyName))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81b741d4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
